var express = require('express');
var router = express.Router();
var {reg,login,isUse,generatorToken} = require("../service/usersService");
/* GET users listing. */
// 注册
router.post('/reg', async function(req, res, next) {
  const { username, password } = req.body;
  const data = await reg({ username, password });
  res.send(data);
});

// 登录
router.get('/login', async function(req, res, next) {
const { username, password } = req.query;
console.log(username, password);

const data = await login({ username, password });
const result = {
  status:false
};
if (data.length) {
  result.status = true;
  result.token = generatorToken(username,password);

}
res.send(result);
});

// 验证用户名
router.post('/isUse', async function(req, res, next) {
  const { username } = req.body;
  const status = await isUse({ username });
  res.send(
    status
  );
});
module.exports = router;
